﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CodeTemplate2.BranchService;
using CodeTemplate2.Models.Employee;

namespace CodeTemplate2.Mapper.Employee
{
    public class BranchMapper
    {
        public BranchModel Mapping(BranchService.BranchDto inputDto)
        {
            BranchModel result = new BranchModel
            {
                Branch_id = inputDto.Id,
                Branch_code = inputDto.Code,
                Branch_name = inputDto.Name,
                Branch_fax = inputDto.Fax,
                Branch_phone = inputDto.Phone
            };

            return result;
        }

        public static List<BranchModel> GetBranchForLookup(String key)
        {

            var result = new List<BranchModel>();
            var service = new BranchService.BranchServiceClient();
            GetAllRequestDto gAllreq = new GetAllRequestDto
            {
                Code = key
            };
            var list = service.GetAll(gAllreq);
            if (list.Data != null && list.Data.Length > 0)
            {
                foreach (var item in list.Data)
                {
                    result.Add(new BranchModel
                    {
                        Branch_id = item.Id,
                        Branch_code = item.Code,
                        Branch_name = item.Name
                    });
                }
            }
            return result;
        }

        public static List<BranchModel> GetBranchAll()
        {

            var result = new List<BranchModel>();
            var service = new BranchService.BranchServiceClient();
            var list = service.GetAll(null);
            if (list.Data != null && list.Data.Length > 0)
            {
                foreach (var item in list.Data)
                {
                    result.Add(new BranchModel
                    {
                        Branch_id = item.Id,
                        Branch_code = item.Code,
                        Branch_name = item.Name
                    });
                }
            }
            return result;
        }
    }
}